﻿// JavaScript source code

var fxrContrls = angular.module('fxrContrls', []);//申明自定义模块

fxrContrls.controller('FxrList', ['$scope','$http', function ($scope,$http) {
    $scope.years = [];
    var date=new Date();
    $scope.selectedName=date.getFullYear();
    for(var i=0;i<10;i++){
        $scope.years.push($scope.selectedName-i);
    }


    //时间选择自动获取echart和table数据源
    $scope.selectChange=function () {
        $scope.GetDataSource();
    }


    $scope.GetDataSource=function(){
		$.ajax({
            type: 'Get',
            url: 'com.cap.cfae.UnderwriteAnaly.getUnderwriteAnalyChart.biz.ext?year='+$scope.selectedName,
//            data: {year:$scope.selectedName},
//            dataType: 'json',
//            contentType: "application/json",
            success: function (data) {
                $scope.$apply(function () {
                    $scope.echartData=data.datas.echartData;
                    $scope.DataSoures=data.datas.tableData;

                    $scope.initChart();
                });
            }
       });
	}
    $scope.GetDataSource();

    //echart初始化
    $scope.initChart=function () {
        var myChart = echarts.init(document.getElementById('myChart'));
        var option = {
            tooltip : {
                trigger: 'axis',
                axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                    type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            legend: {
                data: ['MTN', 'SCP','CP','PPN','PRN','ABN']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis:  {
                type: 'value'
            },
            yAxis: {
                type: 'category',
                nameRotate:100,
                data: $scope.echartData.CXS
            },
            series: [
                {
                    name: 'MTN',
                    type: 'bar',
                    stack: '总量',
                    label: {
                        normal: {
                            show: true,
                            position: 'insideRight'
                        }
                    },
                    data: $scope.echartData.N_1
                },
                {
                    name: 'SCP',
                    type: 'bar',
                    stack: '总量',
                    label: {
                        normal: {
                            show: true,
                            position: 'insideRight'
                        }
                    },
                    data: $scope.echartData.N_2
                },
                {
                    name: 'CP',
                    type: 'bar',
                    stack: '总量',
                    label: {
                        normal: {
                            show: true,
                            position: 'insideRight'
                        }
                    },
                    data: $scope.echartData.N_3
                },
                {
                    name: 'PPN',
                    type: 'bar',
                    stack: '总量',
                    label: {
                        normal: {
                            show: true,
                            position: 'insideRight'
                        }
                    },
                    data: $scope.echartData.N_4
                },
                {
                    name: 'PRN',
                    type: 'bar',
                    stack: '总量',
                    label: {
                        normal: {
                            show: true,
                            position: 'insideRight'
                        }
                    },
                    data: $scope.echartData.N_5
                },
                {
                    name: 'ABN',
                    type: 'bar',
                    stack: '总量',
                    label: {
                        normal: {
                            show: true,
                            position: 'insideRight'
                        }
                    },
                    data: $scope.echartData.N_6
                }
            ]
        };
        myChart.setOption(option);
        //容器自适应
        window.onresize = myChart.resize;

    }

}]);


